#include <iostream>
#include <string>
#include <cmath>

bool isPrime(int num) {
    if (num <= 1) return false;
    for (int i = 2; i <= sqrt(num); ++i) {
        if (num % i == 0) return false;
    }
    return true;
}

int main() {
    std::string words[] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
    std::string input;
    std::cin >> input;

    int number = 0;
    for (int i = 0; i < 10; ++i) {
        if (input == words[i]) {
            number = i;
            break;
        }
    }

    if (number == 0 && input != "zero") {
        std::cout << "Wrong input";
        return 0;
    }

    std::string numStr;
    std::cin >> numStr;

    if (numStr.length() != 3) {
        std::cout << "Wrong input";
        return 0;
    }

    int num = (numStr[0] - '0') * 100 + (numStr[1] - '0') * 10 + (numStr[2] - '0');

    int lower = num;
    int upper = num;

    while (!isPrime(lower) && !isPrime(upper)) {
        --lower;
        ++upper;
    }

    while (!isPrime(lower)) {
        --lower;
    }

    while (!isPrime(upper)) {
        ++upper;
    }

    if (isPrime(lower)) {
        std::cout << lower;
    } else {
        std::cout << upper;
    }

    return 0;
}
